package com.ruoyi.project.good.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.good.domain.GoodSpec;
import com.ruoyi.project.good.service.IGoodSpecService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品规格Controller
 * 
 * @author ruoyi
 * @date 2020-07-01
 */
@RestController
@RequestMapping("/good/spec")
public class GoodSpecController extends BaseController
{
    @Autowired
    private IGoodSpecService goodSpecService;

    /**
     * 查询商品规格列表
     */
    @PreAuthorize("@ss.hasPermi('good:spec:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodSpec goodSpec)
    {
        startPage();
        List<GoodSpec> list = goodSpecService.selectGoodSpecList(goodSpec);
        return getDataTable(list);
    }

    /**
     * 导出商品规格列表
     */
    @PreAuthorize("@ss.hasPermi('good:spec:export')")
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodSpec goodSpec)
    {
        List<GoodSpec> list = goodSpecService.selectGoodSpecList(goodSpec);
        ExcelUtil<GoodSpec> util = new ExcelUtil<GoodSpec>(GoodSpec.class);
        return util.exportExcel(list, "spec");
    }

    /**
     * 获取商品规格详细信息
     */
    @PreAuthorize("@ss.hasPermi('good:spec:query')")
    @GetMapping(value = "/{specId}")
    public AjaxResult getInfo(@PathVariable("specId") Long specId)
    {
        return AjaxResult.success(goodSpecService.selectGoodSpecById(specId));
    }

    /**
     * 新增商品规格
     */
    @PreAuthorize("@ss.hasPermi('good:spec:add')")
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodSpec goodSpec)
    {
        return toAjax(goodSpecService.insertGoodSpec(goodSpec));
    }

    /**
     * 修改商品规格
     */
    @PreAuthorize("@ss.hasPermi('good:spec:edit')")
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodSpec goodSpec)
    {
        return toAjax(goodSpecService.updateGoodSpec(goodSpec));
    }

    /**
     * 删除商品规格
     */
    @PreAuthorize("@ss.hasPermi('good:spec:remove')")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{specIds}")
    public AjaxResult remove(@PathVariable Long[] specIds)
    {
        return toAjax(goodSpecService.deleteGoodSpecByIds(specIds));
    }
}
